﻿using log4net.Config;
using log4net;

namespace FunasrSTT.Common.Helper
{

    public static class LogHelper
    {
        public static ILog LogError;
        public static ILog LogWarn;
        public static ILog LogInfo;
        public static ILog LogDebug;

        static LogHelper()
        {
            string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string path = Path.Combine(baseDirectory, "log4net.config");
            XmlConfigurator.ConfigureAndWatch(new FileInfo(path));
            LogError = LogManager.GetLogger("logerror");
            LogWarn = LogManager.GetLogger("logwarn");
            LogInfo = LogManager.GetLogger("loginfo");
            LogDebug = LogManager.GetLogger("logdebug");
        }

        /// <summary>
        /// 打印错误日志
        /// </summary>
        /// <param name="obj"></param>
        public static void WriteErrorLog(object obj)
        {
            if (LogError.IsErrorEnabled)
            {
                LogError.Error(obj);
            }
        }

        /// <summary>
        /// 打印警告日志
        /// </summary>
        /// <param name="obj"></param>
        public static void WriteWarnLog(object obj)
        {
            if (LogWarn.IsWarnEnabled)
            {
                LogWarn.Warn(obj);
            }
        }

        /// <summary>
        /// 打印信息日志
        /// </summary>
        /// <param name="obj"></param>
        public static void WriteInfoLog(object obj)
        {
            if (LogInfo.IsInfoEnabled)
            {
                LogInfo.Info(obj);
            }
        }

        /// <summary>
        /// 打印调试日志
        /// </summary>
        /// <param name="obj"></param>
        public static void WriteDebugLog(object obj)
        {
            if (LogDebug.IsDebugEnabled)
            {
                LogDebug.Debug(obj);
            }
        }
    }


}
